apiVersion: v1
kind: Service
metadata:
  name: openpitrix-etcd
  namespace: ${NAMESPACE}
  labels:
    app: openpitrix
    tier: etcd
    version: ${VERSION}
spec:
  selector:
    app: openpitrix
    tier: etcd
  ports:
  - name: tcp
    protocol: TCP
    port: 2379
    targetPort: 2379

{% if persistence.enable is defined and persistence.enable == true %} 
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: openpitrix-etcd-pvc
  namespace: ${NAMESPACE}
  labels:
    app: openpitrix
    tier: etcd
spec:
  accessModes:
    - ReadWriteOnce
{% if persistence.storageClass is defined and persistence.storageClass != None %} 
  storageClassName: {{ persistence.storageClass }}
{% endif %}
  resources:
    requests:
      storage: 20Gi
{% endif %}
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: openpitrix-etcd-deployment
  namespace: ${NAMESPACE}
  labels:
    app: openpitrix
    tier: etcd
    version: ${VERSION}
spec:
  selector:
    matchLabels:
      app: openpitrix
      tier: etcd
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: openpitrix
        tier: etcd
        version: ${VERSION}
    spec:
      imagePullSecrets:
      - name: qingcloud 
      containers:
      - name: openpitrix-etcd
        image: {{ etcd_image_repo }}:{{ etcd_image_tag }}
        imagePullPolicy: IfNotPresent
        command: ["etcd", "--data-dir=/data", "--listen-client-urls=http://0.0.0.0:2379", "--advertise-client-urls=http://openpitrix-etcd.${NAMESPACE}.svc:2379", "--max-snapshots=5", "--max-wals=5", "--auto-compaction-retention=168"]
        ports:
        - containerPort: 2379
          name: etcd
        volumeMounts:
        - name: etcd-persistent-storage
          mountPath: /data
      volumes:
      - name: etcd-persistent-storage
{% if persistence.enable is defined and persistence.enable == true %}  
        persistentVolumeClaim:
          claimName: openpitrix-etcd-pvc
{% else %} 
        hostPath:
          path: /var/lib/kubesphere/etcd-data
          type: DirectoryOrCreate
{% endif %}
